"""
chord.__init__

This module provides a location service, allowing clients to map keys to servers in a Chord ring.
"""

class Server(object):
    def __init__(self, finger=None, dict=None):
        if not (finger == None):
            self.ip = finger.ip
            self.port = finger.port
            self.key = finger.key
            self.status = finger.status
        elif not (dict == None):
            self.ip = dict["ip"]
            self.port = dict["port"]
            self.key = dict["key"]
            self.status = dict["status"]
        else:
            self.ip = ""
            self.port = -1
            self.key = ""
            self.status = 'U'
    def to_dict(self):
        return { "ip" : self.ip,
                 "port" : self.port,
                 "key" : self.key,
                 "status" : self.status
                 }
    def __str__(self):
        return "< " + str(self.ip) + ":" + str(self.port) +" @ " + \
                        str(self.key)[:4] + "..., " + self.status + " >"
